const fs = require('fs');
const path = require('path');

function render(res,url,status=200) { //python js 默认值 语法 就是在形参上加个赋值语句
    res.writeHead(status,{
        'Content-Type': 'text/html;charset=utf-8'
    })
    fs.readFile(path.join(__dirname, url),'utf-8', (err, data) => {
        if (err) {
            console.log(err);
        } else {
            res.end(data);
        }
    });
}


function router(url, res) {
  if (url === "/home") {
    render(res,'./static/home.html')
  } else if (url === "/login") {
    render(res,'./static/login.html')
  } else {
    render(res,'./static/404.html',404)
  }
}

module.exports = router;
